package Adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.linefly.online_car.R;

import java.util.List;



/**
 * Created by liheng on 2019/1/22.
 */

public class Adapter_zhalan extends RecyclerView.Adapter<Adapter_zhalan.ViewHolder>  {

private List<String> list1;
private item_click item_click;

public interface item_click{
    void itemclick_xiugai(int position);
    void itemclick_shanchu(int position);
}
    public void setItemClick(Adapter_zhalan.item_click itemClick){
        this.item_click = itemClick;
    }

    public Adapter_zhalan(List<String> list) {
        this.list1 = list;
    }

class ViewHolder extends RecyclerView.ViewHolder {
    TextView textView_mc,textView_sc,textView_xg;

    ViewHolder(View itemView) {
        super(itemView);
        textView_mc = itemView.findViewById(R.id.mingcheng);
        textView_sc = itemView.findViewById(R.id.shanchu);
        textView_xg = itemView.findViewById(R.id.xiugai);





    }
}



    @Override
    public Adapter_zhalan.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rc_zhalan, parent, false);
        Adapter_zhalan.ViewHolder viewHolder = new Adapter_zhalan.ViewHolder(view);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(Adapter_zhalan.ViewHolder holder, final int position) {

        holder.textView_mc.setText(list1.get(position).toString());

        holder.textView_xg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                item_click.itemclick_xiugai(position);
            }
        });

        holder.textView_sc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                item_click.itemclick_shanchu(position);
            }
        });








    }

    @Override
    public int getItemCount() {
        return list1.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }



}
